import service from '../utils/axios'
import type { ApiResponse } from '../utils/axios'

// 学院数据接口
export interface CollegeInfo {
  id: number
  name: string
  createBy?: string
  createTime?: string
  updateBy?: string
  updateTime?: string
}

// 分页查询参数接口
interface CollegeQueryParams {
  name?: string
  page?: number
  size?: number
}

// 分页查询响应接口
interface PageResult<T> {
  data: T[]
  total: number
  page: number
  size: number
}

// 创建/更新学院请求接口
interface CollegeRequest {
  name: string
}

/**
 * 获取所有学院（用于下拉选择）
 */
export function getAllColleges(): Promise<ApiResponse<CollegeInfo[]>> {
  return service({
    url: '/api/colleges/all',
    method: 'get'
  })
}

/**
 * 获取学院列表（分页）
 */
export function getCollegeList(data: CollegeQueryParams): Promise<ApiResponse<PageResult<CollegeInfo>>> {
  return service({
    url: '/api/colleges/query',
    method: 'post',
    data
  })
}

/**
 * 获取学院详情
 */
export function getCollegeById(id: number): Promise<ApiResponse<CollegeInfo>> {
  return service({
    url: `/api/colleges/${id}`,
    method: 'get'
  })
}

/**
 * 创建学院
 */
export function createCollege(data: CollegeRequest): Promise<ApiResponse<{ id: number }>> {
  return service({
    url: '/api/colleges',
    method: 'post',
    data
  })
}

/**
 * 更新学院
 */
export function updateCollege(id: number, data: CollegeRequest): Promise<ApiResponse<void>> {
  return service({
    url: `/api/colleges/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除学院
 */
export function deleteCollege(id: number): Promise<ApiResponse<void>> {
  return service({
    url: `/api/colleges/${id}`,
    method: 'delete'
  })
}













